from functools import reduce
from itertools import product
from typing import *


class Solution:

    def maxProduct(self, words: List[str]) -> int:
        n = len(words)
        h = [0] * n

        def f(w: str) -> int:
            ans = 0
            for c in w:
                ans |= 1 << (ord(c) - ord('a'))
            return ans

        for i, w in enumerate(words):
            h[i] = f(w)

        ans = 0
        for i in range(n):
            for j in range(i):
                if h[i] & h[j] == 0:
                    ans = max(ans, len(words[i]) * len(words[j]))
        return ans


class Solution:

    def maxProduct(self, words: List[str]) -> int:
        masks = [
            reduce(lambda a, b: a | (1 << (ord(b) - ord('a'))), word, 0)
            for word in words
        ]
        return max((len(x[1]) * len(y[1])
                    for x, y in product(zip(masks, words), repeat=2)
                    if x[0] & y[0] == 0),
                   default=0)


# 作者：LeetCode-Solution
# 链接：https://leetcode.cn/problems/aseY1I/solution/dan-ci-chang-du-de-zui-da-cheng-ji-by-le-l5mu/
# 来源：力扣（LeetCode）
# 著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。